import * as THREE from 'three';
import Stats from 'three/examples/jsm/libs/stats.module.js';

export class PerformanceMonitor {
  private stats: Stats;
  public isEnabled: boolean = false;
  
  constructor() {
    this.stats = new Stats();
    this.stats.dom.style.position = 'absolute';
    this.stats.dom.style.top = '0px';
    this.stats.dom.style.left = '0px';
    this.stats.dom.style.zIndex = '100';
  }
  
  public enable(): void {
    if (!this.isEnabled) {
      document.body.appendChild(this.stats.dom);
      this.isEnabled = true;
    }
  }
  
  public disable(): void {
    if (this.isEnabled) {
      document.body.removeChild(this.stats.dom);
      this.isEnabled = false;
    }
  }
  
  public toggle(): void {
    if (this.isEnabled) {
      this.disable();
    } else {
      this.enable();
    }
  }
  
  public update(): void {
    if (this.isEnabled) {
      this.stats.update();
    }
  }
  
  public dispose(): void {
    this.disable();
  }
} 